package com.orangelife.utils;

import java.util.HashMap;
import java.util.Map;

public class UrlPath {

	/***
	 * 地产
	 */
	public static String propInfoUrl = conPath(ProConfig
			.getProValues("SVC_PROPINFOURl"));

	/**
	 * 获取财务系统
	 */
	public static String finAnceUrl = conPath(ProConfig
			.getProValues("SVC_FINANCE"));

	/***
	 * 物业缴费中心
	 */
	public static String feeCenterUrl = conPath(ProConfig
			.getProValues("SVC_FEECENTER"));

	/***
	 * 批量小区
	 */
	public static String bauthComm = propInfoUrl
			+ "orangelife/service/v1.0.0/cmmcommunity/bauthfind";

	/***
	 * 批量单元
	 */
	public static String bauthUnit = propInfoUrl
			+ "orangelife/service/v1.0.0/cmmUnit/bauthfind";

	/***
	 * 楼栋
	 */
	public static String bauthBuild = propInfoUrl
			+ "orangelife/service/v1.0.0/building/bauthfind";

	/***
	 * 批量房屋
	 */
	public static String bauthAparts = propInfoUrl
			+ "orangelife/service/v1.0.0/cmmApartments/bauthfind";

	/***
	 * 搜索小区
	 */
	public static String searComm = propInfoUrl
			+ "orangelife/service/v1.0.0/cmmcommunity/search";

	/**
	 * 获取房屋信息
	 */
	public static String getApartmentInfo = propInfoUrl
			+ "orangelife/service/v1.0.0/cmmApartments/apartmentInfo";

	/***
	 * 根据房号批量查询房屋（单元房屋凭借）
	 */
	public static String bauthFindbuilngUntiApaprt = propInfoUrl
			+ "orangelife/service/v1.0.0/base/bauthFindbuilngUntiApaprt";

	/***
	 * 根据小区查询楼栋
	 */
	public static String getBuilds = propInfoUrl
			+ "orangelife/service/v1.0.0/base/%s/buildings";

	/***
	 * 根据小区查询单元
	 */
	public static String getUnits = propInfoUrl
			+ "orangelife/service/v1.0.0/base/units";

	/***
	 * 根据小区查询单元
	 */
	public static String getApaprtMents = propInfoUrl
			+ "orangelife/service/v1.0.0/base/apartments";

	/***
	 * 根据小区查询单元
	 */
	public static String getOwners = propInfoUrl
			+ "orangelife/service/v1.0.0/base/owners";

	/***
	 * 获取已删除信息
	 */
	public static String hasDeletePropInfo = propInfoUrl
			+ "orangelife/service/v1.0.0/base/hasDeletePropInfo";

	/***
	 * 提交参数到财务系统
	 */

	public static String sendInfoToFinance = finAnceUrl
			+ "sourceinfo/svc/sourceinfo";

	/***
	 * 初始化物业类型
	 */
	public static String initFeeTypes = feeCenterUrl + "feeType/bauthfinds";

	/***
	 * 
	 */
	public static String editReceiptNumStore = feeCenterUrl
			+ "receiptNumStore/editNumStore";

	public static String invalidReceiptNumStore = feeCenterUrl
			+ "receiptNumStore/invalid";

	/**
	 * 修改支付方式
	 */
	public static String editReceiptNumStorePayType = feeCenterUrl
			+ "receiptNumStore/editPayType";

	public static String conurl(String url, String id, Map<String, String> map) {
		StringBuffer buffer = new StringBuffer();

		if (!StringUtils.isBlank(id)) {
			buffer.append(url.replaceAll("\\%s", id)).toString();
		} else {
			buffer.append(url).toString();
		}
		StringBuffer bufferTemp = new StringBuffer();
		if (map != null && map.size() > 0) {
			if (map.size() == 1) {
				for (Map.Entry<String, String> entry : map.entrySet()) {
					bufferTemp.append("?" + entry.getKey() + "="
							+ entry.getValue());
				}
			}
			if (map.size() > 1) {
				String firstKey = null;
				String firstValue = null;
				for (Map.Entry<String, String> entry : map.entrySet()) {
					firstKey = entry.getKey();
					firstValue = entry.getValue();
				}
				bufferTemp.append("?" + firstKey + "=" + firstValue);
				map.remove(firstKey);
				for (Map.Entry<String, String> entry : map.entrySet()) {
					bufferTemp.append("&" + entry.getKey() + "="
							+ entry.getValue());
				}
			}

		}
		return buffer.append(bufferTemp.toString()).toString();
	}

	public static String conPath(String url) {
		if (StringUtils.isBlank(url)) {
			// throw new AppBizException(2, "路径不可为空");
			return null;
		}
		String urlTemp = url.substring(url.length() - 1, url.length());
		if (!urlTemp.equals("/")) {
			url = url + "/";
		}
		return url;
	}

	public static void main(String[] args) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("12", "123");

		System.out.println(UrlPath.conurl("/orangelife/service/sysCoupon",
				null, map));

	}
}
